<template>
  <div class="detail">
     <div class="header">
       <div class="icon" @click="goBack">
         <span class="iconfont icon-arrow-left"></span>
       </div>
       <div class="title">
         {{detailData.title}}
       </div>
     </div>

     <div class="detailTop">
         <div class="title">
            {{detailData.title}}
         </div>
         <div class="pic">
           <img :src="detailData.picurl" alt="">
         </div>
     </div>

     <div class="description">
       {{detailData.description}}
     </div>

     <div class="detailMain" v-html="detailData.content">
     </div>

     <div class="detaInfo">
       <div class="row">分类: <span>{{detailData.className}}</span></div>
       <div class="row">发布时间: <span>{{myDate(detailData.posttime)}}</span></div>
       <div class="row">阅读量: <span>{{detailData.hits}}</span></div>
     </div>
  </div>
</template>

<script>
import { detailFun, getNavFun } from '@/network/innerAxios'
import comm from '@/assets/js/common.js'
export default {
  data () {
    return {
      detailData: [],
      type: 'img',
      id: 0,
      cid: 0
    }
  },
  mounted () {
    this.id = this.$route.query.id
    this.cid = this.$route.query.cid ? this.$route.query.cid : 0
    this.type = this.$route.query.type ? this.$route.query.type : 'img'
    this.getDetailData()
  },
  methods: {
    // 返回
    goBack () {
      this.$router.back()
    },
    async getDetailData () {
      const resData = await detailFun(this.id, this.cid, this.type)
      const cid = resData.data.classid
      const resArr = await getNavFun()
      resArr.data.forEach(item => {
        if (item.id === cid) {
          resData.data.className = item.classname
        } else if (cid == 14) {
          resData.data.className = '灵感创意'
        } else if (cid == 16) {
          resData.data.className = '文章干活'
        }
      })
      this.detailData = resData.data
    },
    myDate (time) {
      return comm.myDate(time, 3)
    }
  }
}
</script>

<style lang="less" scoped>
.detail{
  .header{
    display: flex;
    justify-content: space-between;
    height: 1rem;
    color: #fff;
    background-color: #31C27C;
    align-items: center;
    text-align: center;
    .icon{
      flex: 1;
      span{
        font-size: 0.6rem;
        display: block;
      }
    }
    .title{
      flex: 5;
      font-size: 0.4rem;
      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
      padding-right: 0.4rem;
      padding-left: 0.6rem;
    }
  }
  .detailTop{
    font-size: 0.44rem;
    text-align: justify;
    font-weight: 600;
    color: #333;
    display: flex;
    padding: 0.4rem 0.2rem;
    .title{
      width: 70%;
      padding-right: 0.2rem;
    }
    .pic{
      width: 30%;
      img{
        width: 100%;
        display: block;
      }
    }
  }
  .description{
    font-size: 0.26rem;
    color: #FF8800;
    padding: 0.2rem;
    border-top: 1px solid#FF44AA;
    line-height: 0.5rem;
  }
  .detailMain{
    padding: 0.2rem;
    font-size: 0.32rem;
    color: #00FF99;
  }
  .detaInfo{
    font-size: 0.26rem;
    padding: 0.6rem 0.2rem;
    color: #FF00FF;
    line-height: 2em;
    span{
      font-size: 0.3rem;
      color:#FF44AA;
    }
  }
}
</style>

<style  scoped>
.detailMain >>> img{
    max-width: 100%;
}
</style>
